package com.ym.controller.soso;

import com.github.pagehelper.PageInfo;
import com.ym.common.constant.Constants;
import com.ym.common.utils.page.PageDomain;
import com.ym.common.utils.sensitive.SensitiveFilter;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.service.IStandarTaglibrarySV;
import com.ym.soso.domain.param.CountLabelParam;
import com.ym.soso.domain.param.OrgCommentRecordQueryParam;
import com.ym.soso.domain.param.UserEvaluationParam;
import com.ym.soso.domain.vo.CountLabelVo;
import com.ym.soso.domain.vo.OrgCommentRecordVO;
import com.ym.soso.service.IOrgCommentRecordSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 评价记录Controller
 *
 * @author ym
 * @date 2020-08-20
 */
@Api(tags = "soso-评价")
@RestController
@Validated
@RequestMapping(value = "/soso/comment", headers = Constants.Api.VERSION)
public class OrgCommentRecordController extends BaseController {

	@Autowired
	private IOrgCommentRecordSV orgCommentRecordSV;

	@Autowired
	private IStandarTaglibrarySV standarTaglibrarySV;

	@ApiOperation("用户评价录入")
	@Log
	@PostMapping("/evalInsert")
	public APIResponse evalInsert(@RequestBody @Valid UserEvaluationParam updateParam) {
		if (SensitiveFilter.MY_SQL.contain(updateParam.getContent())) {
			return failMsg("内容包含敏感词汇,请重新编辑发表");
		}
		Long id = orgCommentRecordSV.evalInsert(updateParam);
		return successData(id);
	}

	@ApiOperation("评价统计")
	@Log(dataBase = false, printBody = false, printQuery = true)
	@GetMapping("/countLabel")
	public APIResponse<CountLabelVo> countLabel(@Valid CountLabelParam queryParam) {
		return successData(orgCommentRecordSV.countLabel(queryParam));
	}

	@ApiOperation("评价记录列表")
	@Log
	@GetMapping("/listPageRecord")
	public APIResponse<PageInfo<OrgCommentRecordVO>> listPageRecord(@Valid OrgCommentRecordQueryParam queryParam) {
		PageDomain.startPage();
		List<OrgCommentRecordVO> commentRecordVOS = orgCommentRecordSV.selectListMobile(queryParam);
		return successPage(commentRecordVOS);
	}
}
